"""
聊天模型
定义聊天相关的核心数据模型
"""

from datetime import datetime
from typing import List, Dict, Any, Optional
from pydantic import BaseModel

class ChatMessage(BaseModel):
    """聊天消息模型"""
    role: str  # "user", "assistant", "system"
    content: str
    content_type: str = "text"  # "text", "image", "audio", "video"
    media_url: Optional[str] = None  # 媒体文件URL（如果存储在服务器上）
    timestamp: datetime

class ChatResponse(BaseModel):
    """聊天响应模型"""
    response: str
    session_id: str
    suggestions: List[Dict[str, Any]] = []
    related_knowledge: List[Dict[str, Any]] = []
    quality_score: Optional[float] = None
    source_type: Optional[str] = None

class ChatSession(BaseModel):
    """聊天会话模型"""
    session_id: str
    user_id: str
    messages: List[ChatMessage]
    created_at: datetime
    updated_at: datetime
    # 添加媒体存储信息
    media_storage_info: Optional[Dict[str, Any]] = None
    # 添加上下文信息
    context_info: Optional[Dict[str, Any]] = None
    # 添加用户偏好信息
    user_preferences: Optional[Dict[str, Any]] = None
    # 添加对话状态跟踪
    conversation_state: Optional[Dict[str, Any]] = None
    # 添加对话轮次计数
    turn_count: int = 0
    # 添加对话摘要
    conversation_summary: Optional[str] = None

class ChatSessionResponse(BaseModel):
    """聊天会话响应模型"""
    session_id: str
    messages: List[ChatMessage]
    created_at: datetime